package com.wyy.service.impl;

import com.wyy.bean.Menu;
import com.wyy.dao.MenuDao;
import com.wyy.dao.impl.MenuDaoImpl;
import com.wyy.service.MenuService;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName MenuServiceImpl
 * @Description //TODO
 * @Author wky
 * @Date 2021/9/28 20:53
 * @Version 1.0
 **/
public class MenuServiceImpl implements MenuService {
    
    private MenuDao menuDao = new MenuDaoImpl();
    
    @Override
    public List<Menu> getMenuList() {
        List<Menu> menuList = menuDao.getMenuList();
        List<Menu> newMenuList = new ArrayList<>();

        for (Menu menu : menuList) {
            //如果upMenuId==0 遍历其他菜单 找到二级菜单 加入新集合
            if (menu.getUpmenuId() == 0){
                ArrayList<Menu> secondMenuList = new ArrayList<>();
                for (Menu menu1 : menuList) {
                    if (menu1.getUpmenuId() == menu.getMenuId()){
                        secondMenuList.add(menu1);
                    }
                }
                menu.setSecondMenuList(secondMenuList);
                newMenuList.add(menu);
            }
        }

        return newMenuList;
    }
}
